<?php 
session_start();

require_once 'utils/util.php';
require_once 'controller/referalController.php';

if(!is_loggedin()) {
  header("Location: index.php");
}

?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="css/main-style.css" />
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="js/user-validates.js"></script>
    <title>Social Media Tool - Referal Panel</title>
  </head>
  <body>
    <div id="fb-root"></div>
    <div class="referal-panel-main">
      <h3>You can win BTC inviting to play <span class="bold">BitOnSoccer</span> and <span class="bold">BitOnSoccer - World Cup Bet</span></h3>
      <h4>Welcome <?= $_SESSION['username']; ?>! - <a href="logout.php">Logout</a></h4>
      <div>
        Your referal stats
      </div>
      <table>
        <tr>
          <td>Total of Visits</td>
          <td>Total of referals</td>          
          <td>Total BTC wons</td>
          <td>BTC won on last 30 days</td>
        </tr>
        <tr>
          <td><?= getTotalVisits( $entityManager, $_SESSION['usuId'] ); ?></td>
          <td><?= getTotalReferal( $entityManager, $_SESSION['usuId'] ); ?></td>          
          <td><?= totalBTCWon( $entityManager, $_SESSION['usuId'] ); ?></td>
          <td><?= totalBTCWonLast30Days( $entityManager, $_SESSION['usuId'] ); ?></td>                    
        </tr>                
      </table>
      <table>
        <tr>
          <td colspan="3">Share your referal link on Social Networks</td>
        </tr>
        <tr>
          <td>
            <?php $str = getStrategy( $entityManager, 'facebook' ); ?>
            <?php if( $str > 0 ): ?>
              <div class="fb-share-button" data-href="http://bitonsoccer.com?refcode=<?= $_SESSION['reference_code']; ?>&str=<?= $str; ?>" data-type="button"></div>
            <?php endif; ?>         
          </td>
          <td class="td td2">
            <?php 
              unset($str);
              $str = getStrategy( $entityManager, 'twitter' ); 
            ?>
            <?php if( $str > 0 ): ?>
              <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://bitonsoccer.com?refcode=<?= $_SESSION['reference_code']; ?>&str=<?= $str; ?>" data-text="Come to play with us!" data-via="bitonsoccer" data-related="BitOnSoccer" data-count="none" data-hashtags="BitOnSoccer">Tweet</a>
            <?php endif; ?>             
          </td>
          <td class="td td2">
            <?php 
              unset($str);
              $str = getStrategy( $entityManager, 'googleplus' ); 
            ?>
            <?php if( $str > 0 ): ?>
              <div class="g-plus" data-href="http://bitonsoccer.com?refcode=<?= $_SESSION['reference_code']; ?>&str=<?= $str; ?>" data-action="share" data-annotation="none" data-height="24"></div>
            <?php endif; ?>
          </td>
        </tr>
      </table>
      
      <br />
      
      <table>
        <tr>
          <td>Your referal URL:</td>
        </tr>
        <tr>
          <td>
            <input type="text" size="70" value="http://bitonsoccer.com?refcode=<?= $_SESSION['reference_code']; ?>" />
          </td>
        </tr>                
      </table>
      
      <br />
      
      <table>
        <tr>
          <td>HTML Code:</td>
        </tr>
        <tr>
          <td>
            <textarea rows="2" cols="60"><a href='http://bitonsoccer.com/referal?refcode=<?= $_SESSION['reference_code']; ?>'>Come to play with BitOnSoccer</a></textarea>
          </td>
        </tr>                
      </table>

      <br />

      <table>
        <tr>
          <td>Forum signature Code:</td>
        </tr>
        <tr>
          <td>
            <textarea rows="2" cols="60">[url=http://bitonsoccer.com/referal?refcode=<?= $_SESSION['reference_code']; ?>]Come to play with BitOnSoccer[/url]</textarea>
          </td>
        </tr>                
      </table>
    </div>
  </body>
</html>

<!-- Start Facebook-->
<script>
  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id))
      return;
    js = d.createElement(s);
    js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
</script>
<!-- End Facebook-->

<!-- Start Google Plus -->
<script type="text/javascript">
  (function() {
    var po = document.createElement('script');
    po.type = 'text/javascript';
    po.async = true;
    po.src = 'https://apis.google.com/js/platform.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(po, s);
  })();
</script>
<!-- End Google Plus -->

<!-- Start Twitter -->
<script>
  !function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
    if (!d.getElementById(id)) {
      js = d.createElement(s);
      js.id = id;
      js.src = p + '://platform.twitter.com/widgets.js';
      fjs.parentNode.insertBefore(js, fjs);
    }
  }(document, 'script', 'twitter-wjs');
</script>
<!-- End Twitter -->